﻿/******************************************************************************
* File description: inputMethodEventCatch.h
* Function: 用于处理QML文本框捕获不了输入法信号的问题
* Current Version: 1.0.0
* Author: JNN
* Date: 2025-07-01
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
#ifndef INPUTMETHODEVENTCATCH_H
#define INPUTMETHODEVENTCATCH_H

#include <QObject>
#include <QInputMethodEvent>
#include <QDebug>

// 用于监听输入法的键盘事件
class InputMethodEventCatch : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QObject* target READ target WRITE setTarget NOTIFY targetChanged)

public:
    explicit InputMethodEventCatch(QObject *parent = nullptr);
    ~InputMethodEventCatch();

    QObject *target();

    Q_INVOKABLE void setTarget(QObject *target);
    Q_INVOKABLE void onTargetDestruction();

    bool eventFilter(QObject *obj, QEvent *event);


signals:
    void targetChanged();
    void inputMethodEventPressed(int code, const QString &key);
    void inputMethodEventCommitted(const QString &commitString);

private:
    QObject *m_target = nullptr;
};

#endif // INPUTMETHODEVENTCATCH_H
